package data;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Set;

public class ItemSystemCollection {

  private String         _userPrimaryKey;
  private String         _userName;
  private Set<EVEItem>   _items;
  private Set<EVESystem> _systems;
  private Set<EVEItem>   _deletedItems;
  private Set<EVESystem> _deletedSystems;

  public ItemSystemCollection(String user_id, String username) {
    _userPrimaryKey = user_id;
    _userName = username;
    _items = new HashSet<EVEItem>();
    _systems = new HashSet<EVESystem>();
    _deletedItems = new HashSet<EVEItem>();
    _deletedSystems = new HashSet<EVESystem>();
  }

  public void dump() {
    System.out.println("ID = " + _userPrimaryKey);
    System.out.println("Name = " + _userName);
    System.out.println(_items.size() + " Items: ");

    for (EVEItem item : _items) {
      item.dump();
    }

    System.out.println(_systems.size() + "Systems: ");

    for (EVESystem system : _systems) {
      system.dump();
    }
  }

  @Override
  public int hashCode() {
    final int prime = 31;
    int result = 1;
    result = prime * result + ((_userPrimaryKey == null) ? 0 : _userPrimaryKey.hashCode());
    return result;
  }

  @Override
  public boolean equals(Object obj) {
    if (this == obj) return true;
    if (obj == null) return false;
    if (getClass() != obj.getClass()) return false;
    ItemSystemCollection other = (ItemSystemCollection) obj;
    if (_userPrimaryKey == null) {
      if (other._userPrimaryKey != null) return false;
    }
    else if (!_userPrimaryKey.equals(other._userPrimaryKey)) return false;
    return true;
  }

  public void addItem(EVEItem item) {
    _items.add(item);
  }
  
  public void removeItem(EVEItem item) {
    _items.remove(item);
    _deletedItems.add(item);
  }

  public void addSystem(EVESystem system) {
    _systems.add(system);
  }
  
  public void removeSystem(EVESystem system) {
    _systems.remove(system);
    _deletedSystems.add(system);
  }

  public String getUserPrimaryKey() {
    return _userPrimaryKey;
  }

  public String getUserName() {
    return _userName;
  }
  
  public void setUserPrimaryKey(String key){
    _userPrimaryKey = key;
  }
  
  public Set<EVEItem> getItems(){
    return _items;
  }
  
  public Set<EVESystem> getSystems(){
    return _systems;
  }
  
  public Set<EVEItem> getDeletedItems(){
    return _deletedItems;
  }
  
  public Set<EVESystem> getDeletedSystems(){
    return _deletedSystems;
  }
}
